int cmp(const void *a, const void *b)
{
        if (*(int *)a < *(int *)b) {
                return -1;
        } else {
                return 1;
        }
}

int binsearch(int* nums, int item, int low, int high)
{
        while (low <= high)
        {
                int mid = low + (high - low) / 2;
                int guess = nums[mid];
                if (guess == item) {
                        return 1;
                } else if (guess < item) {
                        low = mid + 1;
                } else {
                        high = mid - 1;
                }
        }
        return -1;
}


int findRepeatNumber(int* nums, int numsSize){
        int i, j;
        qsort(nums, numsSize, sizeof(int), cmp);
        for (i = 0; i < numsSize - 1; i++) {
                if (binsearch(nums, nums[i], i+1, numsSize-1) != -1) {
                        return nums[i];
                }
        }
        return -1;
}
